package l1j.opqlo.Timer.Controler.Server;

import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.Thread.GeneralThreadPool;

/**
 * 城戰計時軸
 *
 * @author dexc
 *
 */
public class ServerWarTimer extends TimerTask {

	private static final Logger _log = Logger.getLogger(ServerWarTimer.class
			.getName());

	private ScheduledFuture<?> _timer;

	@Override
	public void run() {
		try {
			ServerWarExecutor.get().checkWarTime();

		} catch (final Exception e) {
			_log.log(Level.SEVERE, "城戰計時時間軸異常重啟", e);
			GeneralThreadPool.getInstance().cancel(this._timer, false);
			final ServerWarTimer warTimer = new ServerWarTimer();
			warTimer.start();
		}
	}

	public void start() {
		final int timeMillis = 60 * 1000;// 1分鐘
		this._timer = GeneralThreadPool.getInstance().scheduleAtFixedRate(this,
				timeMillis, timeMillis);
	}
}
